package com.xbongbong.saas.enums.dictionary;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 数据字典-联系人级别
 *
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/2/26 10:19
 * @since v1.0
 */
@Getter
public enum ContactLevelEnum {

    // 联系人级别
    HIGH("1", "enum.contactLevel.name.high", "high"),
    MIDDLE("2", "enum.contactLevel.name.middle", "middle"),
    LOW("3", "enum.contactLevel.name.low", "low"),
    ;

    private String code;
    private String name;
    private String attr;

    ContactLevelEnum(String code, String name, String attr) {
        this.code = code;
        this.name = name;
        this.attr = attr;
    }

    /**
     * 通过枚举 code 获得枚举
     *
     * @param code 枚举Code
     *
     * @return ContactLevelEnum
     */
    public static ContactLevelEnum getByCode(String code) {
        for (ContactLevelEnum cacheCode : values()) {
            if (Objects.equals(code, cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return null;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
